cc.Class({
    extends: cc.Component,

    properties: {
        barr:cc.Prefab,
        role:cc.Node,
        //背景图片节点
        backgroundNode: [cc.Node],
        //背景图片精灵
        backgroundSpr: cc.Sprite,        
        //背景滚动速度
        bg_roll_speed:2,
        //碰撞效果预制节点
        bombList: [cc.Prefab],
        //计分
        scoreTxt:cc.Label,
        //跳跃按钮
        jumpBtn:cc.Node,

    },

    onLoad:function(){


        // for (var i = 0; i < 5; i++) {
        //     this.NewBarr();
        // }
        
        // cc.audioEngine.playMusic(this.bgAudio, true);
        //启动碰撞组件管理器
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        this.bgWidth = this.backgroundSpr.spriteFrame.getRect().width;
        this._size = cc.winSize;
    },

    update: function update() {
        //背景滚动
        this.backgroundNode[0].x -= this.bg_roll_speed;
        this.backgroundNode[1].x -= this.bg_roll_speed;
        if (this.backgroundNode[0].x + this.bgWidth / 2 < -this._size.width / 2) {
            this.backgroundNode[0].x = this.backgroundNode[1].x + this.bgWidth - 4;
        }

        if (this.backgroundNode[1].x + this.bgWidth / 2 < -this._size.width / 2) {
            this.backgroundNode[1].x = this.backgroundNode[0].x + this.bgWidth - 4;
        }
    },
    //增加计分
    addScore:function(value){
        // cc.audioEngine.playEffect(this.addScoreAudio, false);
        //sava data
        this.totalScore += value;
        cc.sys.localStorage.setItem('the_score', this.totalScore);
        this.scoreTxt.string = "score:"+this.totalScore;
    },


    //角色跳跃逻辑
    playerMove: function() {
        ////移动过程中暂停节点所有侦听事件
        cc.eventManager.pauseTarget(this.node, true); ///////////
        var goR1 = cc.moveBy(0.25, cc.p(0 , 70));
        var goR2 = cc.moveBy(0.25, cc.p(0, -70));
        //主角动作完成时恢复节点上的触摸侦听事件
        var callFunc = cc.callFunc(function () {
            cc.eventManager.resumeTarget(this.node, true);
        }, this);
        var sque2 = cc.sequence(goR1,goR2, callFunc);
        this.role.runAction(sque2);
    },

});
